package com.huike.controller.sys;

import com.huike.log.Log;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.Role.dtos.RoleDto;
import com.huike.Role.dtos.RolePageDTO;
import com.huike.Role.pojos.Role;
import com.huike.service.sys.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 角色管理接口
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    //条件分页查询角色
    @Log(title = "角色管理模块")
    @PostMapping("/list")
    public Result pageList(@RequestBody RolePageDTO rolePageDTO) {
       PageResult pageResult =  roleService.list(rolePageDTO);
        return Result.success(pageResult);
    }
    //添加角色
    @Log(title = "角色管理模块")
    @PostMapping()
    public Result insert(@RequestBody RoleDto roleDto){
        roleService.saveRole(roleDto);
        return Result.success("成功");
    }
    //修改角色
    @Log(title = "角色管理模块")
    @PutMapping()
    public Result updateRole(@RequestBody RoleDto roleDto){
        roleService.updateRole(roleDto);
        return Result.success("成功");
    }
    @Log(title = "角色管理模块")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
       Role role = roleService.findById(id);
        return Result.success(role);
    }
    @Log(title = "角色管理模块")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        roleService.deleteById(id);
        return Result.success("成功");
    }


}
